package com.cicc.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cicc.springboot.common.dto.R;
import com.cicc.springboot.entity.CurrencyEntity;
import com.cicc.springboot.mapper.CurrencyMapper;
import com.cicc.springboot.service.CurrencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName CurrencyServiceImpl
 * @Description TODO
 * @Author 转轮王
 * @Date 2024/10/9 13:50
 * @Version 1.0
 */


@Service
public class CurrencyServiceImpl implements CurrencyService {


    @Autowired
    private CurrencyMapper currencyMapper;


    /**
     * 查看全部币种
     *
     * @return
     */
    @Override
    public R<String[]> getAllCurrencyName() {
        List<String> currencyNames = currencyMapper.selectList(
                        new LambdaQueryWrapper<CurrencyEntity>().select(CurrencyEntity::getCurrencyName) // 获取货币名称
                ).stream()
                .map(CurrencyEntity::getCurrencyName)
                .collect(Collectors.toList());

        // 将列表转换为数组
        String[] namesArray = currencyNames.toArray(new String[0]);

        return R.ok(namesArray);
    }

}
